package com.zeus.base.smscenter.service.impl;

import com.google.common.collect.Maps;
import com.zeus.base.smscenter.mapper.SmsLogInfoMapper;
import com.zeus.base.smscenter.model.SmsLogInfo;
import com.zeus.base.smscenter.service.ISmsLogInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016-02-19.
 */
@Service
public class SmsLogInfoServiceImpl implements ISmsLogInfoService {

    @Autowired
    private SmsLogInfoMapper smsLogInfoMapper;

    @Override
    public int save(SmsLogInfo smsLogInfo) {
        return smsLogInfoMapper.save(smsLogInfo);
    }

    @Override
    public int update(SmsLogInfo smsLogInfo) {
        return smsLogInfoMapper.update(smsLogInfo);
    }

    /**
     * 短信日志查询
     *
     * @param params
     * @return
     */
    @Override
    public Map<String, Object> find(Map<String, Object> params) {
        Integer page = Integer.valueOf(params.get("page").toString());//当前页
        Integer size = Integer.valueOf(params.get("size").toString());//每页显示条数
        Map<String, Object> resultMap = Maps.newHashMap();
        List<Map<String, Object>> list = smsLogInfoMapper.find(params);//查询集合
        resultMap.put("list", list);
        Map<String, Object> total = new HashMap<String, Object>();
        if (list != null && !list.isEmpty()) {
            if (list.size() > 0) {
                total = smsLogInfoMapper.findCountAndSum(params);//总页数
            } else {
                total.put("total", 0);
            }
        } else {
            total.put("total", 0);
        }
        total.put("pageSize", size);
        total.put("currentPage", page);
        Integer totalPage = (int) Math.ceil(Double.valueOf(total.get("total").toString()) / size);
        total.put("totalPage", totalPage);
        resultMap.put("page", total);
        return resultMap;
    }

    @Override
    public SmsLogInfo findByTenantAndHashContentAndCreateDate(SmsLogInfo smsLogInfo) {
        return smsLogInfoMapper.findByTenantAndHashContentAndCreateDate(smsLogInfo);
    }

    @Override
    public int updateForZt(SmsLogInfo smsLogInfo) {
        return smsLogInfoMapper.updateForZt(smsLogInfo);
    }

    @Override
    public List<SmsLogInfo> findListByCondition(Map<String, Object> params) {
        return smsLogInfoMapper.findListByCondition(params);
    }
}
